package com.ggh.jinjilive.ui.mall.shop;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.ggh.jinjilive.BaseApplication;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.FragmentShopCentreBinding;
import com.ggh.jinjilive.mobile.mall.shop.ShopMessageMobile;
import com.ggh.jinjilive.ui.BaseFragment;
import com.ggh.jinjilive.utils.ARouterUtils;

public class ShopCentreFragment extends BaseFragment<FragmentShopCentreBinding> implements View.OnClickListener {
    //VM
    private MineShopViewModel mineShopViewModel;
    @Override
    public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BaseApplication.getInstance().getAppComponent().doInjectionMain(this);
        mineShopViewModel = new ViewModelProvider(this,viewModelFactory).get(MineShopViewModel.class);
    }

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        return R.layout.fragment_shop_centre;
    }


    @Override
    public void initView() {
        super.initView();

    }

    @Override
    public void initData() {
        super.initData();
        //门店中心
        mineShopViewModel.StoreStoreInfo();
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        //门店中心
        mineShopViewModel.mShopMessageMobile.observe(this, new Observer<ShopMessageMobile>() {
            @Override
            public void onChanged(ShopMessageMobile shopMessageMobile) {
                if(null != shopMessageMobile){
                    //店铺图
                    Glide.with(binding.productImg).load(shopMessageMobile.getImg()).into(binding.productImg);
                    //店铺名称
                    binding.shopName.setText(shopMessageMobile.getName());
                    //状态
                    if(shopMessageMobile.getIs_open() == 1){//运营
                        binding.tvIsOpen.setText("运营中");
                    }else {
                        binding.tvIsOpen.setText("休息");
                    }
                    //可提现金额
                    binding.totalIncome.setText(shopMessageMobile.getWithdrawal_profit() +"");
                    //冻结的资金
                    binding.frozen.setText("冻结的资金：" + shopMessageMobile.getFrozen_profit() + "元");
                    //今日访客数
                    binding.visitorToday.setText(shopMessageMobile.getToday_vistor() +"");
                    //收藏数
                    binding.followedNum.setText(shopMessageMobile.getFollow() +"");
                    //订单数
                    binding.orderNum.setText(shopMessageMobile.getOrder_num()+"");
                }
            }
        });
        //店铺管理
        binding.llShopModification.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ll_shop_modification://店铺管理
                ARouter.getInstance().build(ARouterUtils.ShopModificationActivity)
                        .withSerializable("ShopMessageMobile",mineShopViewModel.mShopMessageMobile.getValue())
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation();
                break;
        }
    }
}
